use "Kam Archer dataset.dta"

***** IVs *****
// demographics
* age
gen ageyears_18 = (2018-birthyr18)
gen age01_18 = (ageyears_18-19)/(93-19)
recode ageyears_18 (19/30 = 1)(31/93=0)(else=.), gen(age1930_18)
recode ageyears_18 (31/50= 1)(19/30 51/93=0)(else=.), gen(age3150_18)
recode ageyears_18 (51/65= 1)(19/50 66/93=0)(else=.), gen(age5165_18)
recode ageyears_18 (66/93= 1)(19/65=0)(else=.), gen(age65pl_18)
  
* female
recode gender18 (1=0 "male")(2=1 "female")(else=.), gen(female_18)
recode gender18 (1=1 "male")(2=0 "female")(else=.), gen(male_18)

* race/ethnicity
recode race18 (1=0 "white")(2=1 "black")(3=2 "Hispanic")(else=.), gen(race3cat_18)
recode race3cat_18 (1=1)(0 2=0)(else=.), gen(black_18) 
recode race3cat_18 (2=1)(0 1=0)(else=.), gen(hisp_18) 
recode race3cat_18 (0=1)(1 2=0)(else=.), gen(white_18) 

* edu
recode educ18 (1=0 "less HS")(2=.25)(3 4=.5)(5=.75)(6=1 "post BA")(else=.), gen(ed5cat_18)

* income: 1-16; 31=$150k or more; 97=incref
recode faminc_new18 (1/3=1)(4/97=0)(else=.), gen(incQ1_18)
recode faminc_new18 (1/3=0)(4/5=1)(6/97=0)(else=.), gen(incQ2_18)
recode faminc_new18 (1/3=0)(4/5=0)(6/8=1)(9/97=0)(else=.), gen(incQ3_18)
recode faminc_new18 (1/3=0)(4/5=0)(6/8=0)(9/16=1)(97=0)(else=.), gen(incQ4_18)
recode faminc_new18 (1/16=0)(97=1)(else=.), gen(incref_18)

* PID
recode pid718 (1=0 "Str Dem")(2=.17)(3=.33)(4 8=.5)(5=.67)(6=.83)(7=1 "Str GOP"), gen(pid7cata_18)
recode pid718 (1 2 3=0 "Dem")(4 8=.5)(5 6 7=1 "GOP")(else=.), gen(pid3cata_18)
recode pid718 (1 2 3=1 "Dem")(5 6 7=0 "GOP")(else=.), gen(dem_18)
recode pid718 (1 2 3=0 "Dem")(5 6 7=1 "GOP")(else=.), gen(gop_18)
recode pid718 (4 8=1 "Ind")(1 2 3 5 6 7=0)(else=.), gen(ind_18)
recode pid718 (1 7=1 "Strong")(2 6=.5)(3 5=0 "Lean")(else=.), gen(strpid_18)

*Ideology
recode ideo518 (1=0 "Very Liberal")(2=.25)(3 6=.5)(4=.75)(5=1 "Very Conservative")(else=.), gen(lc5cata_18)

*modern sexism
recode demand18 (1=1)(2=.75)(3=.5)(4=.25)(5=0)(else=.), gen(sexism1_18)
recode jobs18 (1=0)(2=.25)(3=.5)(4=.75)(5=1)(else=.), gen(sexism2_18)
recode harass18 (1=1)(2=.75)(3=.5)(4=.25)(5=0)(else=.), gen(sexism3_18)
alpha sexism1_18 sexism2_18 sexism3_18  
gen modsexism_18 = (sexism1_18+sexism2_18+sexism3_18)/3
svyset [pw=weight18]
svy: mean modsexism_18
estat sd

//turnout in 2012, 2014, 2016, and 2018
recode vb_vf_g2018 (1/11=1)(else=0), gen(turnout_g2018)

//note that people who are ages 18 & 19 in 2018 were not eligible to vote in 2016
recode tsmart_G2016 (1 2 3 4 5 6 7 8 9 11=1)(else=0), gen(turnout_g2016)
replace turnout_g2016=. if ageyears_18<19

recode tsmart_G2014 (1 2 3 4 5 6 7 8 9 11=1)(else=0), gen(turnout_g2014)
replace turnout_g2014=. if ageyears_18<21

recode tsmart_G2012 (1 2 3 4 5 6 7 8 9 11=1)(else=0), gen(turnout_g2012)
replace turnout_g2012=. if ageyears_18<23

*****TABLE 1*****
svyset [pw=weight18]
svy: mean modsexism_18, over(turnout_g2018)
svy: probit turnout_g2018 modsexism_18
svy: mean modsexism_18, over(pid3cata_18 turnout_g2018) 
svy, subpop(dem_18): reg modsexism_18 turnout_g2018
svy, subpop(ind_18): reg modsexism_18 turnout_g2018
svy, subpop(gop_18): reg modsexism_18 turnout_g2018

//TURNOUT IN 2018
svy: tab turnout_g2018 turnout_g2016, cell
svy: tab turnout_g2018 turnout_g2014, cell
svy: tab turnout_g2018
svy: tab turnout_g2016
svy: tab turnout_g2014

gen modsexpid7_18 = modsexism_18*pid7cata_18
svy: probit turnout_g2018 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 turnout_g2014
est store turnout18

svy, subpop(dem_18): mean turnout_g2014  lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
svy, subpop(gop_18): mean turnout_g2014 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 

//TURNOUT IN 2016
svy: probit turnout_g2016 turnout_g2012 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store turnout16

svy, subpop(dem_18): mean turnout_g2012 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
svy, subpop(gop_18): mean turnout_g2012 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 

//comparing effect of modern sexism in 2018 vs. 2016
suest turnout18 turnout16 
lincom ([turnout18_turnout_g2018]modsexism_18) -([turnout16_turnout_g2016]modsexism_18)
lincom ([turnout18_turnout_g2018]modsexism_18+[turnout18_turnout_g2018]modsexpid7_18) -([turnout16_turnout_g2016]modsexism_18+[turnout16_turnout_g2016]modsexpid7_18)

//turnout in 2018 controlling for turnout in 2016, then both 2014 and 2016
svy: probit turnout_g2018 turnout_g2016 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store turnout18_2
svy: probit turnout_g2018 turnout_g2016 turnout_g2014 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store turnout18_3

//TURNOUT IN 2014
svy: probit turnout_g2014 turnout_g2012 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store turnout14

svy, subpop(dem_18): mean turnout_g2014 turnout_g2012 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
svy, subpop(gop_18): mean turnout_g2014 turnout_g2012 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 

*****TABLE 2*****
est table turnout18 turnout16 turnout18_2 turnout18_3 turnout14, b(%9.2f) se style(col) stats(N) eq(1)
est table turnout18 turnout16 turnout18_2 turnout18_3 turnout14, b(%9.2f) star(.1 .05 .01) style(col) stats(N) eq(1) 


*****FIGURE 1*****
//histogram by party id
gen fweight = round(weight*100)
preserve
keep modsexism_18 pid7cata_18 fweight
rename modsexism_18 observedsexism
save graphingdata.dta, replace
restore
*per http://www.stata.com/statalist/archive/2007-10/msg00327.html

//Predicted Turnout in 2018 with 83.5% CI 
preserve
collapse turnout_g2014 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
replace turnout_g2014=.5
replace pid7cata_18=0
replace lc5cata_18=.25
replace female_18=1
replace black_18=0
replace hisp_18=0
replace ed5cat_18=.5
replace incQ1_18=1
replace incQ2_18=0
replace incQ3_18=0
replace incref_18=0
replace age3150_18=1 
replace age5165_18=0
replace age65pl_18=0
expand 11
egen modsexism_18 = fill(0(.1)1)
lab var modsexism_18 "Modern Sexism"
expand 2
replace turnout_g2014 = .56 in 12/22
replace pid7cata_18=1 in 12/22
replace lc5cata_18=.75 in 12/22
replace female_18=0 in 12/22
replace black_18=0 in 12/22
replace hisp_18=0 in 12/22
replace ed5cat_18=.5 in 12/22
replace incQ1_18=0 in 12/22
replace incQ2_18=0 in 12/22
replace incQ3_18=0 in 12/22
replace incref_18=0 in 12/22
replace age3150_18=0  in 12/22
replace age5165_18=1 in 12/22
replace age65pl_18=0 in 12/22
gen modsexpid7_18 = modsexism_18*pid7cata_18
est restore turnout18
predict p1
predict stdp, stdp
predict Xb, xb
gen ub = normal(Xb+(invnormal(.9175)*stdp))
gen lb = normal(Xb-(invnormal(.9175)*stdp))
append using graphingdata
twoway (connected p1 modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lwidth(medthick)) ///
(connected p1 modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid)  lwidth(medthick)) ///
(connected ub modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected lb modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected ub modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin)) ///
(connected lb modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin)) ///
(histogram observedsexism if pid7cata_18<.5 [fw=fweight], percent lcolor(blue) lpattern(solid) fcolor(none) yaxis(2)) ///
(histogram observedsexism if pid7cata_18>.5 [fw=fweight], percent lcolor(red) lpattern(dash) fcolor(none) yaxis(2)), ///
ytitle("Pr(Turnout 2018)") graphregion(color(white)) title("Turnout in 2018") name(turnout18, replace) legend(order(1 2)) legend(lab(1 "Dem") lab(2 "GOP")) ///
ylabel(0(.2)1, nogrid axis(1)) ylabel(0(20)100, axis(2) labcolor(white) noticks) ytitle(" ", axis(2)) ///
xtitle("Modern Sexism") xlabel(0(.2)1.08) ///
text(.9 1.04 "GOP" .39 1.04 "Dem") legend(off)
restore
graph export turnout18.tif, width(3000) height(2000)

//Predicted Turnout in 2016 with 83.5% CI 
preserve
collapse turnout_g2012 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
replace turnout_g2012=.57
replace pid7cata_18=0
replace lc5cata_18=.25
replace female_18=1
replace black_18=0
replace hisp_18=0
replace ed5cat_18=.5
replace incQ1_18=1
replace incQ2_18=0
replace incQ3_18=0
replace incref_18=0
replace age3150_18=1 
replace age5165_18=0
replace age65pl_18=0
expand 11
egen modsexism_18 = fill(0(.1)1)
lab var modsexism_18 "Modern Sexism"
expand 2
replace turnout_g2012 = .63 in 12/22
replace pid7cata_18=1 in 12/22
replace lc5cata_18=.75 in 12/22
replace female_18=0 in 12/22
replace black_18=0 in 12/22
replace hisp_18=0 in 12/22
replace ed5cat_18=.5 in 12/22
replace incQ1_18=0 in 12/22
replace incQ2_18=0 in 12/22
replace incQ3_18=0 in 12/22
replace incref_18=0 in 12/22
replace age3150_18=0  in 12/22
replace age5165_18=1 in 12/22
replace age65pl_18=0 in 12/22
gen modsexpid7_18 = modsexism_18*pid7cata_18
est restore turnout16
predict p1
predict stdp, stdp
predict Xb, xb
gen ub = normal(Xb+(invnormal(.9175)*stdp))
gen lb = normal(Xb-(invnormal(.9175)*stdp))
append using graphingdata
twoway (connected p1 modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lwidth(medthick)) ///
(connected p1 modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(medthick)) ///
(connected ub modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected lb modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected ub modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin))  ///
(connected lb modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin))  ///
(histogram observedsexism if pid7cata_18<.5 [fw=fweight], percent lcolor(blue) lpattern(solid) fcolor(none) yaxis(2)) ///
(histogram observedsexism if pid7cata_18>.5 [fw=fweight], percent lcolor(red) lpattern(dash) fcolor(none) yaxis(2)), ///
ytitle("Pr(Turnout 2016)") graphregion(color(white)) title("Turnout in 2016") name(turnout16, replace)  ///
ylabel(0(.2)1, nogrid axis(1)) ylabel(0(20)100, axis(2) labcolor(white) noticks) ytitle(" ", axis(2)) ///
xtitle("Modern Sexism") xlabel(0(.2)1.08) ///
text(.95 1.04 "GOP" .66 1.04 "Dem") legend(off)
restore
graph export turnout16.tif, width(3000) height(2000)

//Predicted Turnout in 2014 with 83.5% CI 
preserve
collapse turnout_g2012 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
replace turnout_g2012=.57
replace pid7cata_18=0
replace lc5cata_18=.25
replace female_18=1
replace black_18=0
replace hisp_18=0
replace ed5cat_18=.5
replace incQ1_18=1
replace incQ2_18=0
replace incQ3_18=0
replace incref_18=0
replace age3150_18=1 
replace age5165_18=0
replace age65pl_18=0
expand 11
egen modsexism_18 = fill(0(.1)1)
lab var modsexism_18 "Modern Sexism"
expand 2
replace turnout_g2012 = .63 in 12/22
replace pid7cata_18=1 in 12/22
replace lc5cata_18=.75 in 12/22
replace female_18=0 in 12/22
replace black_18=0 in 12/22
replace hisp_18=0 in 12/22
replace ed5cat_18=.5 in 12/22
replace incQ1_18=0 in 12/22
replace incQ2_18=0 in 12/22
replace incQ3_18=0 in 12/22
replace incref_18=0 in 12/22
replace age3150_18=0  in 12/22
replace age5165_18=1 in 12/22
replace age65pl_18=0 in 12/22
gen modsexpid7_18 = modsexism_18*pid7cata_18
est restore turnout14
predict p1
predict stdp, stdp
predict Xb, xb
gen ub = normal(Xb+(invnormal(.9175)*stdp))
gen lb = normal(Xb-(invnormal(.9175)*stdp))
append using graphingdata
twoway (connected p1 modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lwidth(medthick)) ///
(connected p1 modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(medthick)) ///
(connected ub modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected lb modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue) lpattern(solid) lwidth(vvthin)) ///
(connected ub modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin)) ///
(connected lb modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red) lpattern(solid) lwidth(vvthin)) ///
(histogram observedsexism if pid7cata_18<.5 [fw=fweight], percent lcolor(blue) lpattern(solid) fcolor(none) yaxis(2)) ///
(histogram observedsexism if pid7cata_18>.5 [fw=fweight], percent lcolor(red) lpattern(dash) fcolor(none) yaxis(2)), ///
ytitle("Pr(Turnout 2014)") graphregion(color(white)) title("Turnout in 2014") name(turnout14, replace) legend(order(1 2)) legend(lab(1 "Dem") lab(2 "GOP"))  ///
ylabel(0(.2)1, nogrid axis(1)) ylabel(0(20)100, axis(2) labcolor(white) noticks) ytitle(" ", axis(2)) ///
xtitle("Modern Sexism") xlabel(0(.2)1.08) ///
text(.71 1.04 "GOP" .33 1.04 "Dem") legend(off)
restore
graph export turnout14.tif, width(3000) height(2000)

graph combine turnout18 turnout16 turnout14, ycommon xcommon row(3) xsize(4.5) ysize(9)
graph export figure1b.tif, replace width(3000) height(6000)


//CONTROLLING FOR IDEOLOGY
gen lc5pid7_18 = lc5cata_18*pid7cata_18
svy: probit turnout_g2018 turnout_g2014 modsexpid7_18 modsexism_18 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store basic
svy: probit turnout_g2018 turnout_g2014 modsexpid7_18 modsexism_18 pid7cata_18 lc5pid7_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
est store lcinterxn
est table basic lcinterxn, b(%9.2f) se style(col) stats(N) eq(1)
est table basic lcinterxn, b(%9.2f) star(.1 .05 .01) style(col) stats(N) eq(1) 

preserve
collapse turnout_g2014 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
replace turnout_g2014=.5
replace pid7cata_18=0
replace lc5cata_18=.25
replace female_18=1
replace black_18=0
replace hisp_18=0
replace ed5cat_18=.5
replace incQ1_18=1
replace incQ2_18=0
replace incQ3_18=0
replace incref_18=0
replace age3150_18=1 
replace age5165_18=0
replace age65pl_18=0
expand 11
egen modsexism_18 = fill(0(.1)1)
lab var modsexism_18 "Modern Sexism"
expand 2
replace turnout_g2014 = .56 in 12/22
replace pid7cata_18=1 in 12/22
replace lc5cata_18=.75 in 12/22
replace female_18=0 in 12/22
replace black_18=0 in 12/22
replace hisp_18=0 in 12/22
replace ed5cat_18=.5 in 12/22
replace incQ1_18=0 in 12/22
replace incQ2_18=0 in 12/22
replace incQ3_18=0 in 12/22
replace incref_18=0 in 12/22
replace age3150_18=0  in 12/22
replace age5165_18=1 in 12/22
replace age65pl_18=0 in 12/22
gen modsexpid7_18 = modsexism_18*pid7cata_18
est restore turnout18
predict p1
twoway (connected p1 modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue)) (connected p1 modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red)) , ///
ytitle("Pr(Turnout 2018)") graphregion(color(white)) title("Turnout in 2018") name(turnout18_noci, replace) legend(lab(1 "Dem") lab(2 "GOP"))  ylabel(0(.2)1, nogrid axis(1)) xtitle("Modern Sexism") 
restore


preserve
collapse turnout_g2014 pid7cata_18 lc5cata_18 female_18 black_18 hisp_18 ed5cat_18 incQ1_18 incQ2_18 incQ3_18 incref_18 age3150_18 age5165_18 age65pl_18 
replace turnout_g2014=.5
replace pid7cata_18=0
replace lc5cata_18=.25
replace female_18=1
replace black_18=0
replace hisp_18=0
replace ed5cat_18=.5
replace incQ1_18=1
replace incQ2_18=0
replace incQ3_18=0
replace incref_18=0
replace age3150_18=1 
replace age5165_18=0
replace age65pl_18=0
expand 11
egen modsexism_18 = fill(0(.1)1)
lab var modsexism_18 "Modern Sexism"
expand 2
replace turnout_g2014 = .56 in 12/22
replace pid7cata_18=1 in 12/22
replace lc5cata_18=.75 in 12/22
replace female_18=0 in 12/22
replace black_18=0 in 12/22
replace hisp_18=0 in 12/22
replace ed5cat_18=.5 in 12/22
replace incQ1_18=0 in 12/22
replace incQ2_18=0 in 12/22
replace incQ3_18=0 in 12/22
replace incref_18=0 in 12/22
replace age3150_18=0  in 12/22
replace age5165_18=1 in 12/22
replace age65pl_18=0 in 12/22
gen modsexpid7_18 = modsexism_18*pid7cata_18
gen lc5pid7_18 = lc5cata_18*pid7cata_18
est restore lcinterxn
predict p1
twoway (connected p1 modsexism_18 if pid7cata_18==0, msymbol(i) lcolor(blue)) (connected p1 modsexism_18 if pid7cata_18==1, msymbol(i) lcolor(red)), ///
ytitle("Pr(Turnout 2018)") graphregion(color(white)) title("Turnout in 2018, with Ideology x PID") name(turnout18_intxn, replace) legend(lab(1 "Dem") lab(2 "GOP"))  ylabel(0(.2)1, nogrid)  xtitle("Modern Sexism")
restore

graph combine turnout18_noci turnout18_intxn, altshrink


